﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;

public partial class Admin_VerifyCircuit_VerifyCircuitManager : System.Web.UI.Page
{
    VerifyCircuitManager dllVerifyCircuitManager = new VerifyCircuitManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new DataTable();
    Authentication dllAuthentication = new Authentication();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isAdminLogin();
        this.hlNew.NavigateUrl = "";
        _powerTable = dllAuthentication.getPower(objUserInfo.UserName, "审核流程定义");
        for (int i = 0; i < _powerTable.Rows.Count; i++)
        {
            if (_powerTable.Rows[i]["PowerName"].ToString() == "新建")
            {
                this.hlNew.NavigateUrl = "~/Admin/VerifyCircuit/VerifyCircuit_Add.aspx";
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "删除")
            {
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "查看")
            {
            }
            if (_powerTable.Rows[i]["PowerName"].ToString() == "修改")
            {
            }
        } 
        bindGridView();
    }

    /// <summary>
    /// 绑定GridView
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-1-11</date>
    void bindGridView()
    {
        this.gdvVerifyCircuit.DataSource = dllVerifyCircuitManager.get();
        this.gdvVerifyCircuit.DataBind();
    }


    /// <summary>
    /// 查看明细按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-1-11</date>
    protected void btnVerifyDetail_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        object [] _value = new object[1];
        _value[0] = Convert.ToInt32(this.gdvVerifyCircuit.Rows[i].Cells[0].Text);
        DataTable _detail = dllVerifyCircuitManager.get(VerifyCircuitManager.field.VerifyCircuitId.ToString(), _value);
        bindGridViewDetail(_detail);

        //绑定基本信息
        if (_detail.Rows.Count != 0)
        {
            lbllichengtxt.Visible = true;
            lbllicheng.Visible = true;
            lblpart.Visible = true;
            lblparttxt.Visible = true;
            lbllichengtxt.Text = _detail.Rows[0]["VerifyCircuitName"].ToString();
            lblparttxt.Text = _detail.Rows[0]["DepartmentName"].ToString();
        }

    }


    /// <summary>
    /// 根据读取的datatable绑定审核明细的GridView
    /// </summary>
    /// <param name="_detail">根据id读取审核明细</param>
    /// <author>grokyao</author>
    /// <date>2009-1-11</date>
    void bindGridViewDetail(DataTable _detail)
    {
        DataTable _source = new DataTable();
        for (int i = 1; i <= _detail.Rows.Count; i++)
        {
            string id = "第"+i+"级";
            DataColumn dc = new DataColumn(id);
            _source.Columns.Add(dc);
        }
        DataRow dr = _source.NewRow();
        for (int i = 0; i < _detail.Rows.Count; i++)
        {
            dr[_source.Columns[i].ColumnName] = _detail.Rows[i]["VerifyPeopleRealName"].ToString();            
        }
        _source.Rows.Add(dr);
        this.gdvDetail.DataSource = _source;
        this.gdvDetail.DataBind();

    }


    /// <summary>
    /// 审核流程分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-1-11</date>
    protected void gdvVerifyCircuit_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gdvVerifyCircuit.PageIndex = e.NewPageIndex;
        bindGridView();
    }



    /// <summary>
    /// 删除审核流程按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-1-11</date>
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        object[] _value = new object[1];
        _value[0] = Convert.ToInt32(this.gdvVerifyCircuit.Rows[i].Cells[0].Text);
        int result = dllVerifyCircuitManager.del(VerifyCircuitManager.field.VerifyCircuitId.ToString(), _value);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("删除审核流程未成功，请重试！");
        }
        else
        {
            Response.Redirect("VerifyCircuitManager.aspx");
        }
    }
}
